# Maintainer: Leon White <badfunkstripe@gmail.com>
pkgname=bazel6
pkgver=6.1.0
pkgrel=0
pkgdesc="Bazel is an open-source build and test tool"
url="https://bazel.build/"
arch="all !x86 !armhf !armv7 !riscv64 !s390x !aarch64 !ppc64le"
license="Apache-2.0"
depends="bash openjdk11-jdk"
makedepends="linux-headers python3 unzip zip"
# Bazel binary is thin C++ client with zip file embedded into the binary,
# stripping breaks that: https://github.com/bazelbuild/bazel/issues/11842
options="!strip"
provides="bazel=$pkgver-r$pkgrel"
subpackages="$pkgname-bash-completion"
source="
	https://github.com/bazelbuild/bazel/releases/download/$pkgver/bazel-$pkgver-dist.zip
	0001-Do-not-use-prebuilt-binaries.patch
	0002-Prefer-local_jdk-instead-of-remote_jdk11.patch
	0003-Make-generate_bash_completion-compatible-with-busybo.patch
	0004-Use-nojdk-bazel-for-generating-the-bash-completion.patch
"
builddir="$srcdir/"

build() {
	EMBED_LABEL=$pkgver-$pkgrel \
	EXTRA_BAZEL_ARGS=--tool_java_runtime_version=local_jdk \
		./compile.sh

	./output/bazel build //scripts:bazel-complete.bash
	cp bazel-bin/scripts/bazel-complete.bash output/

	./output/bazel clean --expunge
}

check() {
	# shellcheck disable=SC2046
	./output/bazel build $(\
		./output/bazel query --noshow_progress '//examples/...' \
			| grep -vF \
				-e /android/ \
				-e /windows/ \
				-e :hello-error-prone \
	)
	./output/bazel test \
		//examples/cpp:hello-success_test \
		//examples/java-native/src/test/java/com/example/myproject:custom \
		//examples/java-native/src/test/java/com/example/myproject:hello \
		//examples/java-starlark/src/test/java/com/example/myproject:pass \
		//examples/py_native:test \
		//examples/shell:test

	./output/bazel clean --expunge
}

package() {
	install -Dm 755 -t "$pkgdir/usr/bin" output/bazel
	install -Dm 644 output/bazel-complete.bash \
		"$pkgdir/usr/share/bash-completion/completions/bazel"
}

sha512sums="
222c72b34566229bb96e2936558f5f8078e3999a10af5beaac231d2ada2e7a69444c4174b1f588f8471424c097422faa7a2bc7a402ee78fbd81729f85ba21bfb  bazel-6.1.0-dist.zip
a18fbeccd595ed86f66557d6cd270ccc2bc9b2736b8f1fc2c79e3fe219e5af836f5b73b211ae31df33af2e7c3097e438e88034ffecea41731b2147fed6ee1bf4  0001-Do-not-use-prebuilt-binaries.patch
32019e3ef57e00215e1123b40de78328767b16151d885746086494e27f47648d601971528c8df8c6c1c309928b60629417c2fcdcf085badce6a3a5ea7c3aca34  0002-Prefer-local_jdk-instead-of-remote_jdk11.patch
b0bae27087f8d1da6a455500fc9fb4758ffdeaa27f0b11de720a0607aa3a4d682adfc1286b6385fe53e67296e7af1f61570b6b3093def1e8cee8531c7f4f5f82  0003-Make-generate_bash_completion-compatible-with-busybo.patch
a102371e03345e62e3ecc181382481563be92246bda08d9a6c24964c35d07301a20ecc32d519a9c9d9a6d0827b6773357f9ac756fa01ae685666100f0413d09b  0004-Use-nojdk-bazel-for-generating-the-bash-completion.patch
"
